package br.edu.ifrn.potigol.lang;

import br.edu.ifrn.potigol.lang.Method;
import br.edu.ifrn.potigol.lang.PotigolException;
import br.edu.ifrn.potigol.lang.PotigolObject;
import br.edu.ifrn.potigol.lang.ValueObject;

/**
 * Método especializado de operadores (+, -, *, /, etc).
 */
public abstract class OperatorMethod<T> extends Method {
  @SuppressWarnings("unchecked")
  public PotigolObject call(PotigolObject receiver, PotigolObject arguments[]) throws PotigolException {
    T self = (T) receiver.as(ValueObject.class).getValue();
    T arg = (T) arguments[0].as(ValueObject.class).getValue();
    return perform(self, arg);
  }
  
  public abstract PotigolObject perform(T receiver, T argument) throws PotigolException;
}
